package LinkedListIteratorDemo;

import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;

public class Mian {

	public static void main(String[] args) {
		List<String> lnkList = new LinkedList<>();
		
		lnkList.add("D");
		lnkList.add("H");
		lnkList.add("R");
		lnkList.add("T");
		
		//Initial ListIterator position
		ListIterator<String> it = lnkList.listIterator();
		
		//After calling next
		String nodeVal = it.next();
		System.out.println(nodeVal);
		
		System.out.println("---------------");
		
		//After inserting J
		it.add("J");
		
		//it移动到链表头
		it = lnkList.listIterator();
		//遍历输出链表
		while(it.hasNext()) {
			System.out.println(it.next());
		}
		
		System.out.println("---------------");
		
		//it移动到链表头
		it = lnkList.listIterator();
		//移动it两次到J和H之间
		it.next();
		it.next();
		//删除节点，删除的是it前面的节点
		it.remove();
		
		//it移动到链表头
		it = lnkList.listIterator();
		//遍历输出链表
		while(it.hasNext()) {
			System.out.println(it.next());
		}
		
		
	}

}
